<template>
    <teleport to='body' v-if="dialogExit">
        <div class="teleportStyle">
            <transition name="dialogShadeName">
                <div class="shadeStyle" v-if="dialogShadeExit" @click="dialogCloseBtn"></div>
            </transition>
            <transition name="dialogContentName">
                <div class="dialogStyle" v-if="dialogContentExit" id="testID">
                    <span style="margin-left:5%;">{{dialogContent}}</span>
                    <div class="dialogBtnListtyle">
                        <span class="dialogCloseStyle" @click="dialogCloseBtn">关闭</span>
                        <span class="dialogConfirmStyle" @click="dialogConfirmBtn">确定</span>
                    </div>
                </div>
            </transition>
        </div>
    </teleport>
</template>
<script setup>
import { ref,nextTick,getCurrentInstance} from 'vue'
const { proxy } = getCurrentInstance()
defineEmits(['dialogConfirmBtn'])
const dialogExit = ref(false)
const dialogShadeExit = ref(false)
const dialogContentExit = ref(false)
let dialogContent = ref()

const clickCreateBtn = (val)=>{
    dialogExit.value = true
    dialogContent.value = val
    nextTick(()=>{
        dialogShadeExit.value = true
        dialogContentExit.value = true
    })
}

const dialogConfirmBtn = ()=>{
    proxy.$emit('dialogConfirmBtn')
}

const dialogCloseBtn = ()=>{
    dialogContentExit.value = false
    dialogShadeExit.value = false
    setTimeout(() => {
        dialogExit.value = false
    }, 200);
}
defineExpose({//父组件可以直接使用
    clickCreateBtn,
    dialogCloseBtn,
})
</script>
<style scoped lang="scss">
.teleportStyle{
    z-index: 999;
    user-select: none;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    overflow: hidden;
    .shadeStyle{
        width: 100%;
        height: 100%;
        background-color: rgba(34, 34, 34, 0.616);
    }
    .dialogStyle{
        border-radius: 6px;
        padding-top: 4%;
        position: absolute;
        height: 11rem;
        padding-left: 1rem;
        padding-right: 1rem;
        width: calc(60% - 2rem);
        left: 20%;
        top: 5rem;
        background-color: white;
        .dialogBtnListtyle{
            width: calc(100% - 2rem);
            position: absolute;
            bottom: 10%;
            display: flex;
            justify-content: space-between;
            span{
                flex: 1;
                text-align: center;
                margin: 0 5%;
                padding: 5px;
                border-radius: 5px;
                padding-left: 10px;
                padding-right: 10px;
                color: white;
            }
            .dialogCloseStyle{
                background-color: rgb(182, 106, 36);
            }
            .dialogConfirmStyle{
                background-color: rgba(36, 96, 209,1);
            }
        }
    }
}
.dialogContentName-enter-active {
    transition: all .2s ease-out;
}

.dialogContentName-leave-active {
    transition: all .2s cubic-bezier(1, 0.5, 0.8, 1);
}

.dialogContentName-enter-from{
    transform: translateY(-100%);
    opacity: 0;
}
.dialogContentName-leave-to{
    transform: translateX(100%);
    opacity: 0;
}
.dialogShadeName-enter-active,.dialogShadeName-leave-active{
    transition: all .2s ease-out;
}
.dialogShadeName-enter-from,.dialogShadeName-leave-to{
    opacity: 0;
}
</style>